set(CMAKE_CROSSCOMPILING ON)

set(CMAKE_SYSTEM_NAME "Darwin")

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
set(CMAKE_OSX_SYSROOT "/osxcross/target/SDK/MacOSX14.sdk")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")

set(CMAKE_INSTALL_NAME_TOOL "xcrun install_name_tool")
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang)
execute_process(COMMAND xcrun -find ar OUTPUT_VARIABLE CMAKE_AR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun -find nm OUTPUT_VARIABLE CMAKE_NM OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun -find ranlib OUTPUT_VARIABLE CMAKE_RANLIB OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun -find strip OUTPUT_VARIABLE CMAKE_STRIP OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(COMMAND xcrun -find ld OUTPUT_VARIABLE CMAKE_LINKER OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_C_FLAGS "--target=darwin -fuse-ld=${CMAKE_LINKER}")
set(CMAKE_CXX_FLAGS "--target=darwin -fuse-ld=${CMAKE_LINKER}")
